<template>
  <resource-table
    :table-columns="tableColumns"
    status-column-label="状态"
    :use-topping-column="true"
    :use-operation-column="true"
    operations="edit,view,delete"
    :operation-column-width="150"
    @queryTable="queryTable"
    @switchStatus="switchStatus"
    @topRow="topRow"
    v-loading="loading"
  >
    <template #headerLeft>
      <el-button type="primary" size="medium">新增</el-button>
      <el-button type="primary" size="medium" style="margin-left: 0"
        >新增1</el-button
      >
    </template>
    <template #headerRight="props">
      <div>
        行政区划：
        <el-select v-model="props.queryParameters.region" placeholder="请选择">
          <el-option
            v-for="item in regions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div>
        名称：
        <el-input
          placeholder="请输入名称，支持模糊查询"
          style="width: 200px"
          v-model="props.queryParameters.name"
        ></el-input>
      </div>
    </template>
    <template #operation>
      <el-tooltip
        effect="dark"
        content="编辑内容"
        placement="top"
        class="col-btn-item"
      >
        <i class="el-icon-edit"></i>
      </el-tooltip>
    </template>
  </resource-table>
</template>

<script>
export default {
  name: "ResourceTableExample",
  data() {
    return {
      tableUrl: "",
      regions: [
        {
          value: "510000",
          label: "四川省",
        },
        {
          value: "130000",
          label: "河北省",
        },
      ],
      value: "",
      inputValue: "",
      tableColumns: [
        {
          prop: "date",
          label: "日期",
        },
        {
          prop: "name",
          label: "姓名",
        },
        {
          prop: "address",
          label: "地址",
        },
        {
          prop: "money",
          label: "金额",
          align: "right",
        },
      ],
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          money: 432,
          status: false,
          topping: true,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
          money: 432,
          status: false,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
          money: 432,
          status: false,
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
          money: 432,
          status: true,
        },
      ],
      loading: false,
    };
  },
  methods: {
    queryTable: function (queryParameters, callback) {
      console.log(queryParameters);
      this.loading = true;

      setTimeout(() => {
        this.loading = false;
        callback(this.tableData);
      }, 3000);
      // callback(this.tableData);
    },
    switchStatus: function (rowInfo) {
      console.log(rowInfo);
    },
    topRow: function (rowInfo, callback) {
      this.tableData[0].topping = false;

      this.tableData.splice(0, 0, {
        date: "2016-05-03",
        name: "王小虎1",
        address: "上海市普陀区金沙江路 1516 弄",
        money: 432,
        status: true,
        topping: 1,
      });
      callback();
    },
  },
};
</script>

<style scoped lang="scss"></style>
